package com.msl.debezium.schedule;

import com.msl.debezium.dto.UserDto;
import com.msl.debezium.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Component
public class DebeziumTestTask {

    private Logger logger = LoggerFactory.getLogger(DebeziumTestTask.class);

    @Autowired
    private UserService userService;

    @Scheduled(cron = "0 0 0/1 * * ?")
    public void inserTask(){

        Date date = new Date();
        logger.info("执行DebeziumTestTask的inserTask定时任务开始！");
        List<UserDto> list = new ArrayList();
        for(int i=0; i<1; i++){
            UserDto userDto = new UserDto();
            userDto.setUsername("debezium-test");
            userDto.setPassword("123");
            userDto.setCreatedAt(date);
            userDto.setUpdatedAt(date);
            list.add(userDto);
        }
        userService.addUser(list);
        logger.info("执行DebeziumTestTask的inserTask定时任务结束！");
    }

}
